<script>
  var longestCommonPrefix = function(strs) {
    let len = Number.MAX_SAFE_INTEGER;
    strs.map(str => {
        len = Math.min(len, str.length)
    })

    let result = '';

    for (let i = 0; i < len; i++) {
        const length = strs.length;
        const s = strs[0][i];
        let count = 0;
        console.log(s)
        strs.map(item => {
            if (item[i] === s) {
                count++
            }
        })
        console.log(count)
        if (count === length) {
            result += s
        } else {
          break;
        }
    }

    return result;
  };

  longestCommonPrefix(['cir', 'car'])
</script>